home *** CD-ROM | disk | FTP | other *** search
/ Workbench Design / WB Collection.iso / workbench werkzeuge / bildschirmschoner / beyondthedark / developer / source / btdlibstuff.asm < prev    next >
Assembly Source File  |  1996-04-07  |  4KB  |  259 lines

  1. ;
  2. ;    Beyond The Dark: Generic Library Startup Code
  3. ;
  4. ;    (c) Copyright 1995 Matthias Scheler
  5. ;        All Rights Reserved
  6. ;
  7.  
  8.         CSECT text,0
  9.  
  10.         NOLIST
  11.         INCLUDE    "exec/types.i"
  12.         INCLUDE    "exec/libraries.i"
  13.         INCLUDE    "exec/resident.i"
  14.         INCLUDE    "exec/initializers.i"
  15.         INCLUDE    "exec/semaphores.i"
  16.         INCLUDE    "dos/dos.i"
  17.         LIST
  18.  
  19. ;    Macros
  20.  
  21. XLIB:        MACRO
  22.         XREF _LVO\1
  23.         ENDM
  24.  
  25. CALL:        MACRO
  26.         jsr _LVO\1(a6)
  27.         ENDM
  28.  
  29. ;    External References
  30.  
  31.         XREF    _LinkerDB
  32.  
  33.         XREF    _MyBlankerName
  34.         XREF    _MyBlankerID
  35.         XREF    _MyBlankerLibInit
  36.         XREF    _MyBlankerLibFree
  37.  
  38.         XREF    _QueryMyBlanker
  39.         XREF    _InitMyBlanker
  40.         XREF    _EndMyBlanker
  41.         XREF    _AnimMyBlanker
  42.         XREF    _PenCountMyBlanker
  43.  
  44.         XLIB    Remove
  45.         XLIB    FreeMem
  46.         XLIB    CloseLibrary
  47.         XLIB    OpenLibrary
  48.         XLIB    InitSemaphore
  49.         XLIB    ObtainSemaphore
  50.         XLIB    ReleaseSemaphore
  51.  
  52. ;    External Definitions
  53.  
  54.         XDEF    _SysBase
  55.  
  56. ;    Our Library Structure
  57.  
  58.         STRUCTURE BTDBase,LIB_SIZE
  59.         BPTR    BB_SegList
  60.         STRUCT    BB_Semaphore,SS_SIZE
  61.         LABEL    BB_SIZE
  62.  
  63. ;    Program Code
  64.  
  65.         moveq    #-1,d0
  66.         rts
  67.  
  68. ;    Library Resident Module Tag
  69.  
  70. LibResTag:    dc.w    RTC_MATCHWORD
  71.         dc.l    LibResTag
  72.         dc.l    LibResTag+RT_SIZE
  73.         dc.b    RTF_AUTOINIT
  74.         dc.b    VERSION
  75.         dc.b    NT_LIBRARY
  76.         dc.b    0
  77.         dc.l    _MyBlankerName,_MyBlankerID
  78.         dc.l    LibInit
  79.  
  80. ;    Initialization Table for Library Structure
  81.  
  82. LibInit:    dc.l    BB_SIZE
  83.         dc.l    FuncTab
  84.         dc.l    DataTab
  85.         dc.l    Init
  86.  
  87. FuncTab:    dc.l    Open
  88.         dc.l    Close
  89.         dc.l    Expunge
  90.         dc.l    ReturnNull
  91.  
  92.         dc.l    QueryMyBlanker
  93.         dc.l    InitMyBlanker
  94.         dc.l    EndMyBlanker
  95.         dc.l    AnimMyBlanker
  96.         dc.l    PenCountMyBlanker
  97.  
  98.         dc.l    -1
  99.  
  100. DataTab:    INITBYTE LN_TYPE,NT_LIBRARY
  101.                 INITLONG LN_NAME,_MyBlankerName
  102.                 INITBYTE LIB_FLAGS,LIBF_SUMUSED+LIBF_CHANGED
  103.                 INITWORD LIB_VERSION,VERSION
  104.                 INITWORD LIB_REVISION,REVISION
  105.                 INITLONG LIB_IDSTRING,_MyBlankerID
  106.                 dc.l    0
  107.  
  108. ;    Init Function
  109.  
  110. Init:        movem.l    a4/a5,-(sp)
  111.         lea    _LinkerDB,a4
  112.  
  113.         move.l    d0,a5
  114.         move.l    a0,BB_SegList(a5)
  115.         move.l    a6,_SysBase(a4)
  116.  
  117.         lea    BB_Semaphore(a5),a0
  118.         CALL    InitSemaphore
  119.  
  120.         move.l    a5,d0
  121.         movem.l    (sp)+,a4/a5
  122.         rts
  123.  
  124. ;    Open Function
  125.  
  126. Open:        movem.l    d2/a4-a6,-(sp)
  127.         lea    _LinkerDB,a4
  128.         move.l    a6,d2
  129.         move.l    a6,a5
  130.         move.l    _SysBase(a4),a6
  131.  
  132.         lea    BB_Semaphore(a5),a0
  133.         CALL    ObtainSemaphore
  134.  
  135.         addq.w    #1,LIB_OPENCNT(a5)
  136.         bclr    #LIBB_DELEXP,LIB_FLAGS(a5)
  137.  
  138.         cmp.w    #1,LIB_OPENCNT(a5)
  139.         bne.s    InitDone
  140.  
  141.         jsr    _MyBlankerLibInit
  142.         tst.l    d0
  143.         bne.s    InitDone
  144.  
  145.         subq.w    #1,LIB_OPENCNT(a5)
  146.         moveq    #0,d2
  147.  
  148. InitDone:    lea    BB_Semaphore(a5),a0
  149.         CALL    ReleaseSemaphore
  150.  
  151.         move.l    d2,d0
  152.         movem.l    (sp)+,d2/a4-a6
  153.         rts
  154.  
  155. ;    Close Function
  156.  
  157. Close:        movem.l    a4-a6,-(sp)
  158.         lea    _LinkerDB,a4
  159.         move.l    a6,a5
  160.         move.l    _SysBase(a4),a6
  161.  
  162.         lea    BB_Semaphore(a5),a0
  163.         CALL    ObtainSemaphore
  164.  
  165.         subq.w    #1,LIB_OPENCNT(a5)
  166.         bne.s    KeepLibrary
  167.  
  168.         jsr    _MyBlankerLibFree
  169.  
  170.         btst    #LIBB_DELEXP,LIB_FLAGS(a6)
  171.         bne.s    KeepLibrary
  172.  
  173.         lea    BB_Semaphore(a5),a0
  174.         CALL    ReleaseSemaphore
  175.         movem.l    (sp)+,a4-a6
  176.         bra.s    TimeToGo
  177.  
  178. KeepLibrary:    lea    BB_Semaphore(a5),a0
  179.         CALL    ReleaseSemaphore
  180.         movem.l    (sp)+,a4-a6
  181.  
  182. ReturnNull:    moveq    #0,d0
  183.         rts
  184.  
  185. ;    Expunge Function
  186.  
  187. Expunge:        tst.w    LIB_OPENCNT(a6)
  188.                 beq.s    TimeToGo
  189.  
  190.                 bset    #LIBB_DELEXP,LIB_FLAGS(a6)
  191.                 bra.s    ReturnNull
  192.  
  193. TimeToGo:    movem.l d2/a4-a6,-(sp)
  194.         lea    _LinkerDB,a4
  195.         move.l    BB_SegList(a6),d2
  196.  
  197.         move.l    a6,a5
  198.         move.l    a5,a1
  199.         move.l    _SysBase(a4),a6
  200.         CALL    Remove
  201.  
  202.         move.l    a5,a1
  203.         moveq    #0,d0
  204.         move.w    LIB_NEGSIZE(a5),d0
  205.         sub.w    d0,a1
  206.         add.w    LIB_POSSIZE(a5),d0
  207.         CALL    FreeMem
  208.  
  209.         move.l    d2,d0
  210.         movem.l    (sp)+,d2/a4-a6
  211.         rts
  212.  
  213. ;    own Library functions
  214.  
  215. ;    return BlankerInfo
  216.  
  217. QueryMyBlanker:    lea    _QueryMyBlanker(pc),a1
  218.         bra.s    Stub
  219.  
  220. ;    create MyBlanker structure
  221.  
  222. InitMyBlanker:    lea    _InitMyBlanker(pc),a1
  223.         bra.s    Stub
  224.  
  225. ;    free MyBlanker structure
  226.  
  227. EndMyBlanker:    lea    _EndMyBlanker(pc),a1
  228.         bra.s    Stub
  229.  
  230. ;    count required pens
  231.  
  232. PenCountMyBlanker:
  233.         lea    _PenCountMyBlanker(pc),a1
  234.         bra.s    Stub
  235.  
  236. ;    draw a frame with MyBlanker structure
  237.  
  238. AnimMyBlanker:    lea    _AnimMyBlanker(pc),a1
  239.  
  240. ;    call C function
  241.  
  242. Stub:        move.l    a4,-(sp)
  243.         lea    _LinkerDB,a4
  244.  
  245.         move.l    a0,-(sp)
  246.         jsr    (a1)
  247.         addq.w #4,sp
  248.  
  249.         move.l    (sp)+,a4
  250.         rts
  251.  
  252. ;    Data
  253.  
  254.         CSECT data,1
  255.  
  256. _SysBase:    dc.l    0
  257.  
  258.         END
  259.